package com.suncp.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author suncp
 * @date 2020/12/12 18:32
 */
@Controller
@RequestMapping("/user")
public class LoginController {

    @RequestMapping(value = "/main")
    public String main() {
        return "main";
    }

    @RequestMapping(value = "/toLogin")
    public String toLogin() {
        return "login";
    }

    @RequestMapping("/login")
    public String login(HttpSession session, String username, String password, Model model) {
        //把用户的信息存在seesion中:

        session.setAttribute("userLoginInfo", username);
        model.addAttribute("username", username);
        return "main";
    }

    @RequestMapping("/toOut")
    public String login(HttpSession session) {
        // 删除session,拦截器直接跳转登录页面
        session.removeAttribute("userLoginInfo");
        return "main";
    }
}
